<template>
	<view class="recharge">
		<view class="recharge-title">
			充值金额
		</view>

		<view class="recharge-money">
			<view class="recharge-money-item" v-for="(item,index) in moneyList" :key="index"
				:class="activeIndex == index?'active':''" @click="selectMoney(index)">
				<view class="recharge-item-money">
					{{ item.meetTheAmount }}<span>元</span>
				</view>

				<view class="recharge-item-tip">
					{{item.name}}
				</view>
			</view>


		</view>

		<view class="recharge-title h-m-t-20">
			充值说明
		</view>
		<view class="recharge-tip">
			<view>1.充值所得金额仅该小程序可用。</view>
			<view>2.该充值功能未调用微信支付，点击充值即可。</view>
			<view>3.充值后仍可申请提现。</view>
		</view>

		<view class="recharge-buttom-box">
			<view class="buttom-left">
				<view class="buttom-left-info">付款金额</view>
				<view class="buttom-left-money">¥ {{ moneyList[activeIndex].meetTheAmount }}</view>
			</view>

			<view class="buttom-right" @click="okEvent">
				立即充值
			</view>
		</view>

	</view>
</template>

<script>
	import {
		wechatPromotionList,
		wechatPromotionRecharge
	} from "@/api/system/wechat"
	// import {updateUserMoney} from '@/utils/api.js'
	export default {
		data() {
			return {
				moneyList: [],
				activeIndex: 0,
			};
		},

		onLoad() {
			this.initList();
		},
		methods: {
			initList() {

				wechatPromotionList({
					isShow: 1
				}).then(res => {
					if (res.code == 200) {
						var data = res.rows;
						this.moneyList = data;
					}
					// createBy: null
					// createTime: "2024-03-04 16:57:46"
					// founder: "1"
					// giftAmount: 0
					// id: 1
					// isShow: 1
					// meetTheAmount: 30
					// name: "30"
					// remark: null
					// updateBy: null
					// updateTime: null
				})
			},
			/* 选择充值金额 */
			selectMoney(index) {
				this.activeIndex = index
			},
			okEvent() {
				let money = this.moneyList[this.activeIndex].meetTheAmount + this.moneyList[this.activeIndex].giftAmount
				wechatPromotionRecharge({
					openId: uni.getStorageSync("openid"),
					money: money
				}).then(res => {
					if (res.code == 200) {
						this.$modal.msgSuccess("充值成功")
						uni.navigateBack();
					}
					// createBy: null
					// createTime: "2024-03-04 16:57:46"
					// founder: "1"
					// giftAmount: 0
					// id: 1
					// isShow: 1
					// meetTheAmount: 30
					// name: "30"
					// remark: null
					// updateBy: null
					// updateTime: null
				}).catch(error => {
					this.$modal.msgError(error)
				})
			}
		}
	}
</script>

<style lang="scss">
	.recharge {
		margin: 30rpx;

		.recharge-title {
			color: #333333;
			font-weight: bold;
		}

		.recharge-tip {
			margin-top: 20rpx;

			view {
				font-size: 28rpx;
				color: #666666;
				margin-top: 10rpx;
			}
		}

		.recharge-money {
			display: flex;
			align-items: center;
			overflow: hidden;
			overflow-x: scroll;
			margin-top: 10rpx;

			.recharge-money-item:first-child {
				margin-left: 0;
			}

			.recharge-money-item {
				margin: 20rpx 10rpx;
				width: 280rpx;
				height: 360rpx;
				border: 2rpx solid #efefef;
				border-radius: 30rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				box-sizing: border-box;
				box-shadow: #f0f0f0 0px 1px 8px 0;
				flex-shrink: 0;

				.recharge-item-money {
					font-size: 60rpx;
					color: #333;

					span {
						font-size: 28rpx;
					}
				}

				.recharge-item-tip {
					padding: 6rpx 16rpx;
					font-size: 24rpx;
					background: #efefef50;
					border-radius: 40rpx;
					margin-top: 20rpx;
					color: #666666;
				}
			}

			.active {
				background-image: url("");
				background-size: 100% 100%;
				background-repeat: no-repeat;
				border: none;
			}
		}

		.recharge-buttom-box {
			position: fixed;
			bottom: 0;
			width: calc(100vw - 60rpx);
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 80rpx;
			padding-top: 20rpx;
			border-top: 2rpx dashed #efefef;
			box-sizing: border-box;

			.buttom-left {
				font-size: 28rpx;
				display: flex;
				align-items: flex-end;

				.buttom-left-money {
					font-weight: bold;
					font-size: 40rpx;
					margin-left: 20rpx;
					line-height: 38rpx;
				}

				.buttom-left-money::first-letter {
					font-weight: normal;
					font-size: 28rpx;
				}
			}

			.buttom-right {
				padding: 16rpx 58rpx;
				background: #333;
				color: #fff;
				border-radius: 50rpx;
				font-size: 28rpx;
				font-weight: bold;
			}
		}
	}
</style>